//
//  UIImage+iphone5.m
//  BlockReach
//
//  Created by mac on 12-11-8.
//  Copyright (c) 2012年 hc. All rights reserved.
//

#import "UIImage+iphone5.h"

@implementation UIImage (iphone5)

+(UIImage*)imageWithName:(NSString*)img{
    CGSize size = [[UIScreen mainScreen] currentMode].size;
    if((int)size.height == 1136) {
        img = [img stringByReplacingOccurrencesOfString:@"@2x" withString:@""];
        NSArray *names = [img componentsSeparatedByString:@"."];
        img = [NSString stringWithFormat:@"%@-568h.%@",names[0],names[1]];
    }
    return [UIImage imageNamed:img];
}
+ (UIImage *)imageByApplyingAlpha:(CGFloat)alpha  image:(UIImage*)image
{
    UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0f);
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGRect area = CGRectMake(0, 0, image.size.width, image.size.height);
    
    CGContextScaleCTM(ctx, 1, -1);
    CGContextTranslateCTM(ctx, 0, -area.size.height);
    
    CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
    
    CGContextSetAlpha(ctx, alpha);
    
    CGContextDrawImage(ctx, area, image.CGImage);
    
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return newImage;
}
@end
